import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path';
import { viteMockServe } from 'vite-plugin-mock';

const baseProxyUrl = "https://liberty-one.libertymutual.com.cn";

function pathResolve(dir: string) {
    return resolve(process.cwd(), '.', dir);
}

// https://vitejs.dev/config/
export default defineConfig(({ command }) => {
    console.log('command=======', command)
    console.log('command=======', command === 'serve' && true)
    return {
        build: {
            sourcemap: command === 'serve' ? 'inline' : false
        },
        // base: '/',
        base:command === 'serve' ?  '/' : '/360/web/',
        plugins: [
            vue(),
            viteMockServe({
                // 忽略以 '_' 开头的API请求，不进行mock处理
                ignore: /^\_/,
                // 指定mock文件目录
                mockPath: 'mock',
                // 是否在本地开发环境启用 mock功能
                // localEnabled: command === 'serve' && true,
                localEnabled: false,
                // 如果你的mock文件是TypeScript格式，则开启此选项
                supportTs: true,


            }),
            // styleImport({
            //     libs: [
            //         {
            //             libraryName: "vant",
            //             esModule: true,
            //             resolveStyle: (name: any) => `vant/es/${name}/style`,
            //         },
            //     ],
            // }),
        ],
        resolve: {
            alias: [
                // /@/xxxx => src/xxxx
                {
                    find: /\/@\//,
                    replacement: pathResolve('src') + '/',
                },
            ]
        },
        css: {
            preprocessorOptions: {
                scss: {
                    additionalData: `@import "./src/css/mixins.scss";`
                },
            },
            // postcss: {
            //     plugins: [
            //         require('postcss-px-to-viewport')({
            //             viewportWidth: 750, // (Number) The width of the viewport.
            //             viewportHeight: 1334, // (Number) The height of the viewport.
            //             unitPrecision: 3, // (Number) The decimal numbers to allow the REM units to grow to.
            //             viewportUnit: "vw", // (String) Expected units.
            //             selectorBlackList: [".ignore", ".hairlines"], // (Array) The selectors to ignore and leave as px.
            //             minPixelValue: 1, // (Number) Set the minimum pixel value to replace.
            //             mediaQuery: false, // (Boolean) Allow px to be converted in media queries.
            //             exclude: [/node_modules/i], //过滤插件
            //             overrideBrowserslist: ['> 0.5%', 'last 2 versions', 'ie > 11', 'iOS >= 9', 'Android >= 5']
            //         })
            //     ],
            // }
        },

        server: {
            proxy: {
                '/couponApi': {
                    // 所要代理的目标地址
                    target: baseProxyUrl,
                    changeOrigin: true,
                },
                "/reports": {
                    //测试
                    target: baseProxyUrl,
                    changeOrigin: true,
                },
                "/auth": {
                    target: baseProxyUrl,
                    changeOrigin: true,
                },
                "/scrm": {
                    target: baseProxyUrl,
                    // target: 'http://10.132.30.166:8001',
                    changeOrigin: true,
                },
                "/platform": {
                    target: baseProxyUrl,
                    changeOrigin: true,
                },
                "/exhibition": {
                    // target: 'http://10.132.30.166:9006',
                    target: baseProxyUrl,
                    changeOrigin: true,
                },
                "/nonmotor": {
                    target: baseProxyUrl,
                    changeOrigin: true,
                },
                "/motor": {
                    target: baseProxyUrl,
                    changeOrigin: true,
                }


            },
        },
    }
})
